package com.concurrency.waitNotify;

import java.util.List;
import java.util.Vector;

public class Consumer extends Thread{
	List<String> goods;
	
	public Consumer(List<String> goods){
		this.goods = goods;
	}

	public void run(){
		synchronized(goods){
			while(true){
				try {
					while(goods.size()==0){
						goods.wait();//该线程在此暂停！同时释放了锁。
					}
					if(goods.size()!=0)
						goods.remove(0);
					Thread.sleep(500);
					System.out.println("Consumer当前goods数量:"+goods.size());
					goods.notify();//唤醒其他线程开始访问goods，由于该线程仍持有锁，故其他线程阻塞。
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}

	}
}
